package tv.danmaku.ijk.media.player.misc;

import android.annotation.TargetApi;
import android.text.TextUtils;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import tv.danmaku.ijk.media.player.IjkMediaMeta.IjkStreamMeta;

public class IjkMediaFormat implements IMediaFormat {
    static abstract class Formatter {

        private Formatter() {

        }

        protected abstract String doFormat(IjkMediaFormat arg1);

        public String format(IjkMediaFormat arg3) {
            String v0 = this.doFormat(arg3);
            if(TextUtils.isEmpty(((CharSequence)v0))) {
                v0 = this.getDefaultString();
            }

            return v0;
        }

        protected String getDefaultString() {
            return "N/A";
        }
    }

    public static final String CODEC_NAME_H264 = "h264";
    public static final String KEY_IJK_BIT_RATE_UI = "ijk-bit-rate-ui";
    public static final String KEY_IJK_CHANNEL_UI = "ijk-channel-ui";
    public static final String KEY_IJK_CODEC_LONG_NAME_UI = "ijk-codec-long-name-ui";
    public static final String KEY_IJK_CODEC_PIXEL_FORMAT_UI = "ijk-pixel-format-ui";
    public static final String KEY_IJK_CODEC_PROFILE_LEVEL_UI = "ijk-profile-level-ui";
    public static final String KEY_IJK_FRAME_RATE_UI = "ijk-frame-rate-ui";
    public static final String KEY_IJK_RESOLUTION_UI = "ijk-resolution-ui";
    public static final String KEY_IJK_SAMPLE_RATE_UI = "ijk-sample-rate-ui";
    public final IjkStreamMeta mMediaFormat;
    private static final Map sFormatterMap;

    static {
        sFormatterMap = new HashMap();
    }

    public IjkMediaFormat(IjkStreamMeta arg4) {

        IjkMediaFormat.sFormatterMap.put("ijk-codec-long-name-ui", new IjkMediaFormat.Formatter(){

            public String doFormat(IjkMediaFormat arg3) {
                return IjkMediaFormat.this.mMediaFormat.getString("codec_long_name");
            }
        });
        IjkMediaFormat.sFormatterMap.put("ijk-bit-rate-ui", new Formatter() {
            @Override
            protected String doFormat(IjkMediaFormat arg6) {
                String v0_1;
                int v0 = arg6.getInteger("bitrate");
                if(v0 <= 0) {
                    v0_1 = null;
                }
                else if(v0 < 1000) {
                    v0_1 = String.format(Locale.US, "%d bit/s", Integer.valueOf(v0));
                }
                else {
                    v0_1 = String.format(Locale.US, "%d kb/s", Integer.valueOf(v0 / 1000));
                }

                return v0_1;
            }
        });
        IjkMediaFormat.sFormatterMap.put("ijk-profile-level-ui", new Formatter() {
            protected String doFormat(IjkMediaFormat arg4) {
                String v0 = arg4.getString("codec_profile");
                if(TextUtils.isEmpty(((CharSequence)v0))) {
                    v0 = null;
                }
                else {
                    StringBuilder v1 = new StringBuilder();
                    v1.append(v0);
                    v0 = arg4.getString("codec_name");
                    if(!TextUtils.isEmpty(((CharSequence)v0)) && (v0.equalsIgnoreCase("h264"))) {
                        int v0_1 = arg4.getInteger("codec_level");
                        if(v0_1 < 10) {
                            return v1.toString();
                        }
                        else {
                            v1.append(" Profile Level ");
                            v1.append(v0_1 / 10 % 10);
                            if(v0_1 % 10 != 0) {
                                v1.append(".");
                                v1.append(v0_1 % 10);
                            }
                        }
                    }

                    v0 = v1.toString();
                }

                return v0;
            }
        });
        IjkMediaFormat.sFormatterMap.put("ijk-pixel-format-ui", new Formatter() {
            @Override
            protected String doFormat(IjkMediaFormat arg2) {
                return arg2.getString("codec_pixel_format");
            }
        });
        IjkMediaFormat.sFormatterMap.put("ijk-resolution-ui", new Formatter() {
            @Override
            protected String doFormat(IjkMediaFormat arg11) {
                String v0_1;
                int v9 = 2;
                int v0 = arg11.getInteger("width");
                int v1 = arg11.getInteger("height");
                int v2 = arg11.getInteger("sar_num");
                int v3 = arg11.getInteger("sar_den");
                if(v0 <= 0 || v1 <= 0) {
                    v0_1 = null;
                }
                else {
                    if(v2 > 0 && v3 > 0) {
                        Locale v4 = Locale.US;
                        Object[] v6 = new Object[4];
                        v6[0] = Integer.valueOf(v0);
                        v6[1] = Integer.valueOf(v1);
                        v6[v9] = Integer.valueOf(v2);
                        v6[3] = Integer.valueOf(v3);
                        v0_1 = String.format(v4, "%d x %d [SAR %d:%d]", v6);
                        return v0_1;
                    }

                    Locale v2_1 = Locale.US;
                    v0_1 = String.format(v2_1, "%d x %d", Integer.valueOf(v0), Integer.valueOf(v1));
                }

                return v0_1;
            }
        });
        IjkMediaFormat.sFormatterMap.put("ijk-frame-rate-ui", new Formatter() {
            @Override
            protected String doFormat(IjkMediaFormat arg3) {
                int v0 = arg3.getInteger("fps_num");
                int v1 = arg3.getInteger("fps_den");
                String v0_1 = v0 <= 0 || v1 <= 0 ? null : String.valueOf((((float)v0)) / (((float)v1)));
                return v0_1;
            }
        });
        IjkMediaFormat.sFormatterMap.put("ijk-sample-rate-ui", new Formatter() {
            @Override
            protected String doFormat(IjkMediaFormat arg6) {
                int v0 = arg6.getInteger("sample_rate");
                String v0_1 = v0 <= 0 ? null : String.format(Locale.US, "%d Hz", Integer.valueOf(v0));
                return v0_1;
            }
        });
        IjkMediaFormat.sFormatterMap.put("ijk-channel-ui", new Formatter() {
            @Override
            protected String doFormat(IjkMediaFormat arg7) {
                String v0_1;
                int v0 = arg7.getInteger("channel_layout");
                if(v0 <= 0) {
                    v0_1 = null;
                }
                else if((((long)v0)) == 4) {
                    v0_1 = "mono";
                }
                else if((((long)v0)) == 3) {
                    v0_1 = "stereo";
                }
                else {
                    v0_1 = String.format(Locale.US, "%x", Integer.valueOf(v0));
                }

                return v0_1;
            }
        });
        this.mMediaFormat = arg4;
    }

    @TargetApi(value=16) public int getInteger(String arg2) {
        int v0 = this.mMediaFormat == null ? 0 : this.mMediaFormat.getInt(arg2);
        return v0;
    }

    public String getString(String arg2) {
        String v0;
        if(this.mMediaFormat == null) {
            v0 = null;
        }
        else if(IjkMediaFormat.sFormatterMap.containsKey(arg2)) {
            v0 =((Formatter) IjkMediaFormat.sFormatterMap.get(arg2)).format(this);
        }
        else {
            v0 = this.mMediaFormat.getString(arg2);
        }

        return v0;
    }
}

